package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("UserOrderConreoller")
@RequestMapping("/user/order")
@Api(tags = "C端-订单相关接口")
@Slf4j
public class OrderConreoller {
    @Autowired
    private OrderService orderService;
    /**
     * 用户下单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> addOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单提交的数据：{}",ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.addOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    /**
     * C端-分页查询历史订单
     *
     *
     *
     * @return
     */
    @ApiOperation("C端-分页查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> getHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("历史订单查询参数--->{}",ordersPageQueryDTO);
        PageResult pageResult = orderService.getHistoryOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * C端-根据订单id查询订单
     * @param id
     * @return
     */
    @ApiOperation("C端-根据订单id查询订单")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> getOrderDetailById(@PathVariable("id") Long id){
        OrderVO orderVO = orderService.getOrderById(id);
        return Result.success(orderVO);
    }

    /**
     * C端-根据订单id取消订单
     * @param id
     * @return
     */
    @ApiOperation("C端-根据订单id取消订单")
    @PutMapping("/cancel/{id}")
    public Result CancelOrderById(@PathVariable("id") Long id){
        log.info("要取消的订单 id: {}",id);
        orderService.CancelOrderById(id);
        return Result.success();
    }


    /**
     * C端-再来一单
     * @param id
     * @return
     */
    @ApiOperation("C端-再来一单")
    @PostMapping("/repetition/{id}")
    public Result OneMoreOrder(@PathVariable("id") Long id){
        orderService.OneMoreOrder(id);
        return Result.success();
    }


    /**
     * C端-客户催单
     * @param id
     * @return
     */
    @ApiOperation("C端-催单")
    @GetMapping("/reminder/{id}")
    public Result ReminderOrder(@PathVariable("id") Long id){
        orderService.ReminderOrder(id);
        return Result.success();
    }

}
